<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>职工详情</title>
</head>
</html>
<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">职工详情</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>职工详情</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="empinformation-search-key">
                <option value="">-请选择-</option>
                <option value="user_id">ID</option>
                <option value="fullName">职工名称</option>
                <option value="phone">手机号</option>
            </select>&emsp;
            <input id="empinformation-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="empinformation-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
            </button>
            <button id="empinformation-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
            <button id="empinformation-btn-export" class="layui-btn icon-btn"><i class="layui-icon">&#xe601;</i>导出
            </button>
        </div>

        <table class="layui-table" id="empinformation-table" lay-filter="empinformation-table"></table>
    </div>
</div>


<!-- 表格操作列 -->
<script type="text/html" id="empinformation-table-bar">
    <a style='margin-top: -3px' class="layui-btn  layui-btn-sm" lay-event="edit">修改</a>
    <a style='margin-top: -3px' class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除</a>
</script>

<!-- 表格状态列 -->
<script type="text/html" id="empinformation-tpl-state">
    <input type="checkbox" lay-filter="empinformation-tpl-state" value="{{d.id}}" lay-skin="switch" lay-text="正常|锁定"
           {{d.enabled==true?'checked':''}}/>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;

        //if( admin.hasPerm('employee:add') ) {
        //   $('#btnAdd').hide();
        //}
        // 添加按钮绑定权限
        if (!admin.hasPerm('user:post/users/saveOrUpdate')) {
            $('#concurrent-btn-add').hide();
        }
        // 导出按钮绑定权限
        if (!admin.hasPerm('user:post/users/exportUser')) {
            $('#concurrent-btn-export').hide();
        }

        // 渲染表格
        table.render({
            elem: '#empinformation-table',
            // url: config.base_server + 'user_query.json',
            url: config.base_server + 'api-employee/empinformation/empinformation',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                // {field: 'id', sort: true, title: '用户编号'},
                {field: 'fullName', sort: true, title: '姓名'},
                {
                    sort: true, title: '性别', templet: function (d) {
                        return d.sex == 0 ? "男" : "女"
                    }, width: 50
                },
                // <img p-bind="src:{{headImgUrl}}"  class="layui-nav-img">
                {
                    field: 'icon', title: '附件', align: 'center', sort: false,
                    templet: function (d) {
                        return '<div style="margin-top: -3px"><img class="layui-nav-img" src=' + d.icon + ' ></div>'
                    }
                },
                // {field:'<img p-bind=\'src:{{icon}}\'  class=\'layui-nav-img\'>', title: '头像'},
                // {field: 'icon', sort: true, title: '头像'},
                {field: 'phone', sort: true, title: '联系电话'},
                {field: 'email', sort: true, title: '邮箱'},
                {field: 'applyPosition', sort: true, title: '应聘职位'},
                {field: 'schoolName', sort: true, title: '毕业学校'},
                {field: 'skills', sort: true, title: '专业技能'},
                {field: 'projectEp', sort: true, title: '项目经历'},
                {field: 'workYears', sort: true, title: '工作年限', width: 50},
                {field: 'epSalary', sort: true, title: '期望薪资', width: 55},

                {
                    sort: true, title: '学历', templet: function (d) {
                        if (d.education == 0) {
                            return "高中及以下"
                        } else if (d.education == 1) {
                            return "大专"
                        } else if (d.education == 2) {
                            return "本科"
                        }
                        return "研究生"
                    }, width: 60
                },
                {
                    sort: true, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                    , width: 170
                },
                // {field: 'status', sort: true, templet: '#empinformation-tpl-state', title: '状态',width: 100},
                {
                    sort: true, title: '状态', templet: function (d) {
                        return d.status == 0 ? "<div style='margin-top: -3px' class='layui-btn layui-btn-primary layui-border-green  '>正常</div>" : "<div style='margin-top: -3px' class='layui-btn layui-btn-disabled '>关闭</div>"
                    }, width: 100
                },
                {
                    sort: true, title: '邀请状态', templet: function (d) {
                        return d.inStatus == 0 ? "<div style='margin-top: -3px' class='layui-btn layui-btn-primary layui-border-blue '>待邀请</div>" : "<div style='margin-top: -3px' class='layui-btn layui-btn-primary layui-border-green layui-btn-radius '>待面试</div>"
                    }, width: 120
                },
                // {field: 'invitationStatus', sort: true, templet: '#empinformation-tpl-state', title: '邀请状态',width: 100},
                {align: 'center', toolbar: '#empinformation-table-bar', title: '操作', width: 135}
            ]]
        });

        // 添加按钮点击事件
        $('#empinformation-btn-add').click(function () {
            showEditModel();
        });

        var showEditModel = function (data) {
            admin.putTempData('employee', data);
            console.log(99999999999, data);
            var title = data ? '修改简历' : '添加简历';
            admin.popupCenter({
                title: title,
                path: 'pages/employee/empinformation_form.html',
                finish: function () {
                    table.reload('empinformation-table', {});
                },
                offset: ['10%', '30%'],
                area: ['50%', '75%'],
                // content: ["@Url.Action("Add")", 'no'],
                maxmin: true
            });
        };

        // 工具条点击事件
        table.on('tool(empinformation-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'edit') { // 修改
                showEditModel(data);
            } else if (obj.event === 'delete') { //删除
                doDelete(obj);
            }

        });
        // 删除
        var doDelete = function (obj) {
            layer.confirm('确定要删除吗？', function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('api-employee/empinformation/delete/' + obj.data.id, {}, function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 500});
                        obj.del();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 500});
                    }
                }, 'DELETE');
            });
        };


        // 搜索按钮点击事件
        $('#empinformation-btn-search').click(function () {
            var key = $('#empinformation-search-key').val();
            var value = $('#empinformation-search-value').val();
            table.reload('empinformation-table', {where: {searchKey: key, searchValue: value}});
        });


        // 导出
        $('#empinformation-btn-export').click(function () {
            var url = config.base_server + 'api-employee/empinformation/empinformation/exportUser?access_token=' + config.getToken().access_token;
            var xhr = new XMLHttpRequest();
            xhr.open('POST', url, true);
            xhr.responseType = "blob";
            xhr.setRequestHeader("client_type", "DESKTOP_WEB");
            xhr.onload = function () {
                if (this.status == 200) {
                    var blob = this.response;
                    var objecturl = URL.createObjectURL(blob);
                    window.location.href = objecturl;
                }
            }
            xhr.send();
        });

        // 修改被面试人状态
        form.on('switch(empinformation-tpl-state)', function (obj) {
            layer.load(2);
            admin.req('api-employee/empinformation/empinformation/updateEnabled', {
                id: obj.elem.value,
                enabled: obj.elem.checked ? true : false
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                    $(obj.elem).prop('checked', !obj.elem.checked);
                    form.render('checkbox');
                }
            }, 'GET');
        });
    });
</script>